#!/bin/bash

source tools/kill_qemu.sh

#find linux -name *.ko | xargs -i sudo cp {} share/modules


if [ "$1" == "arm" ]
then
	qemu-system-arm \
	-M vexpress-a9 \
	-smp 4 \
	-m 1024M \
	-kernel linux/arch/arm/boot/zImage \
	-append "rdinit=/linuxrc user_debug=0xff earlyprintk memblock=debug console=ttyAMA0 loglevel=8" \
	-dtb linux/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \
	-nographic \
	--fsdev local,id=kmod_dev,path=$PWD/share,security_model=none -device virtio-9p-device,fsdev=kmod_dev,mount_tag=kmod_mount \
	-S -s |tee linux.log &
elif [ "$1" == "arm64" ]
then
	qemu-system-aarch64 \
	-machine virt \
	-smp 2 \
	-m 1024M \
	-cpu cortex-a57 \
	-machine type=virt \
	-nographic \
	-kernel linux/arch/arm64/boot/Image \
	-append "rdinit=/linuxrc user_debug=0xff earlyprintk memblock=debug console=ttyAMA0 loglevel=8" \
	--fsdev local,id=kmod_dev,path=$PWD/share,security_model=none -device virtio-9p-device,fsdev=kmod_dev,mount_tag=kmod_mount \
	-S -s |tee linux.log &
else
	echo "unkonw argument"
	exit 1
fi
sleep 2
gnome-terminal -e "eclipse"
